package com.sunyur.tailor.channel.service.inner.receiveorder.service.impl;

import com.alibaba.fastjson.JSON;
import com.sunyur.tailor.channel.common.inner.base.MsgResultCode;
import com.sunyur.tailor.channel.common.inner.base.SunyurResult;
import com.sunyur.tailor.channel.common.middle.base.ChannelResult;
import com.sunyur.tailor.channel.common.middle.enums.MiddleResultEnum;
import com.sunyur.tailor.channel.common.middle.util.ChannelResultUtil;
import com.sunyur.tailor.channel.service.inner.base.SunyurEventService;
import com.sunyur.tailor.channel.service.middle.receiveorder.MiddleReceiveOrderService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: HuBaoding
 * @Description:
 * @Date: Created in 15:05 2021/7/14
 */
@Service
public class SunyurReceiveOrderEntranceServiceImpl implements SunyurEventService {
    private static final Logger LOGGER_INFO = LoggerFactory.getLogger(SunyurReceiveOrderEntranceServiceImpl.class);
    private static final Logger LOGGER_ERROR = LoggerFactory.getLogger(SunyurReceiveOrderEntranceServiceImpl.class);

    @Autowired
    private MiddleReceiveOrderService middleReceiveOrderService;

    /**
     * 收货单创建
     *
     * @param param
     * @return
     * @throws Exception
     */
    public SunyurResult<Boolean> create(String param) throws Exception {
        LOGGER_INFO.info("SunyurReceiveOrderEntranceServiceImpl create param:{}", param);
        SunyurResult<Boolean> result = new SunyurResult<>(false);
        if (StringUtils.isBlank(param)) {
            result.setErrorMessage(MiddleResultEnum.PARAM_NULL.getCode(), MiddleResultEnum.PARAM_NULL.getValue());
        } else {
            MsgResultCode msgResultCode = JSON.parseObject(param, MsgResultCode.class);
            ChannelResult<Boolean> channelResult = middleReceiveOrderService.create(msgResultCode);
            result.setErrorMessage(channelResult.getCode(), channelResult.getMessage());
            if (ChannelResultUtil.isSuccess(channelResult)) {
                result.setContent(true);
            }
        }
        LOGGER_INFO.info("SunyurReceiveOrderEntranceServiceImpl create return:{}", JSON.toJSONString(result));
        return result;
    }

}
